package com.tangbao.goods.service.impl;

import com.tangbao.goods.mapper.ShopcarMapper;
import com.tangbao.goods.model.Shopcar;
import com.tangbao.goods.service.ShopcarService;
import com.tangbao.util.Page;
import com.tangbao.util.ResEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.ws.rs.core.Response;
import java.util.List;

/**
 * 创建人： tangbao
 * 创建时间： 2019/1/2 19:26
 * 功能：
 */
@Service
public class ShopcarServiceImpl implements ShopcarService {
    @Resource
    ShopcarMapper shopcarMapper;


    /**
     * 描述：获取购物车数据
     *
     * @param goodsIds    商品id字符串
     * @param sort        排序字段
     * @param currentPage 当前页
     * @param pageSize    页大小
     *                    返回值：javax.ws.rs.core.Response
     * @throw 创建人：tangbao
     * 创建时间：2019/1/2 19:24
     * 修改人和信息：
     */
    @Override
    public Response getGoodsById(String goodsIds, String sort, Integer currentPage, Integer pageSize) {
        Page page = new Page();
        if(null != currentPage) {
            page.setCurrentPage(currentPage);
        }
        if(null != pageSize) {
            page.setPageSize(pageSize);
        }

        Integer totalCount = shopcarMapper.getShopcarCount(goodsIds);
        page.setTotalCount(totalCount);

        List<Shopcar> shopcarList = shopcarMapper.getShopcarByAll(goodsIds,sort,page.getStart(),page.getPageSize());
        page.setList(shopcarList);
        ResEntity entity = ResEntity.okEntity().put("page", page);
        return Response.ok(entity).build();
    }
}
